import React, { useState } from 'react'
import { Modal, message } from 'antd'
import CollectionCreateForm from './CollectionCreateForm'
import { addProcess } from '@/apis/process'

const CollectionCreateFormModal = ({ open, onCancel }) => {
  const [formInstance, setFormInstance] = useState()

  const handleCreate = async () => {

    const values = await formInstance?.validateFields()
    // console.log(values)
    const formData = new FormData()
    formData.append('algor_name', values.algor_name)
    formData.append('c_num', values.c_num)
    formData.append('c_type', values.c_type)
    formData.append('i_time', parseInt(values.i_time))
    formData.append('s_time', parseInt(values.s_time))
    formData.append('w_type', values.w_type)
    addProcess(formData)
    // onCreate()
    onCancel()
  }

  return (
    <Modal
      open={open}
      title="新增运行"
      okText="确定"
      cancelText="取消"
      okButtonProps={{
        autoFocus: true,
      }}
      onCancel={onCancel}
      destroyOnClose
      onOk={handleCreate}
    >
      <CollectionCreateForm
        onFormInstanceReady={(instance) => {
          setFormInstance(instance)
        }}
      />
    </Modal>
  )
}

export default CollectionCreateFormModal